package com.example.activity;

import com.ab.view.listener.AbOnListViewListener;
import com.ab.view.pullview.AbPullListView;
import com.example.fragment.MainActivity;
import com.benchi.ncar.R;
import com.example.tools.IsNetWork;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

public class OrderOrDetailActivity extends Activity {

	protected long mLastTime = 0;
	private AbPullListView mAbPullListView = null;
	private View mHeadView;
	private WebView webview;
	protected ProgressDialog mProgressDialog;
	private TextView mTvResh;
	private String mUrl = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initViews();
		initData();
	}

	private void showWaitingDialog() {
		mProgressDialog = ProgressDialog.show(this, "", "正在加载...", true, true);
	}

	private void initViews() {
		webview = (WebView) findViewById(R.id.web_main);
		// 设置WebView属性，能够执行Javascript脚本
		webview.getSettings().setJavaScriptEnabled(true);
	}

	private void initData() {
		mUrl = getIntent().getStringExtra("url");
		if ( mUrl != null && mUrl.contains("http")) {
			showWaitingDialog();
			// 加载需要显示的网页
			webview.loadUrl(mUrl);
			// 设置Web视图
			webview.setWebViewClient(new HelloWebViewClient());
			webview.setWebChromeClient(new WebChromeClient() {
				public void onProgressChanged(WebView view, int progress) {
					if (progress == 100) {
						if (mProgressDialog != null) {
							mProgressDialog.dismiss();
						}
					}
				}
			});
		} 
	}

	// Web视图
	private class HelloWebViewClient extends WebViewClient {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			view.loadUrl(url);
			if (!url.equals("")) {
				mUrl = url;
			}
			return true;
		}
	}

	@Override
	protected void onDestroy() {
		if (webview != null) {
			webview.destroy();
		}
		super.onDestroy();
	}
}
